﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cn.Edwon.Web.Support;
using System.Reflection;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Cellula.Client;
using Cn.Cellula.Biz;
using Cn.Cellula.Model.Security;
using Cn.Cellula.Client.ControlHelper;

namespace Cn.Cellula.Website.Admin.User.AddressBook {
    public partial class List1 : PageSupport {
        IUserBiz biz = BizFactory.Get<IUserBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            GvHelper.AppendEventHandler(ref this.gv_list);
            if (!Page.IsPostBack) {
                InitForm();
                LoadUsers();
            }
        }
        private void InitForm() {

        }
        private void LoadUsers() {
            String hql = " from VSysUserEO eo where eo.OwnerKey='" + this.OwnerKey + "' "
                + " and eo.UserKey<>'" + BizConst.Admin.KEY + "' "
                + " and eo.UserKey<>'" + BizConst.Guest.KEY + "' ";
            if (!String.IsNullOrEmpty(this.txt_UserName.Text)) {
                hql += " and eo.UserName like '%" + this.txt_UserName.Text + "%' ";
            }
            if (!String.IsNullOrEmpty(this.hid_Dept.Value)) {
                hql += " and eo.DeptKey = '" + this.hid_Dept.Value + "' ";
            }
            if (!String.IsNullOrEmpty(this.txt_Mobile.Text)) {
                hql += " and eo.Mobile = '" + this.txt_Mobile.Text + "' ";
            }
            if (!String.IsNullOrEmpty(this.txt_Mobile.Text)) {
                hql += " and eo.Qq = '" + this.txt_QQ.Text + "' ";
            }
            hql += " order by eo.UserName ";
            IList<VSysUserEO> list = biz.Find<VSysUserEO>(hql);
            this.gv_list.DataSource = list;
            this.gv_list.Attributes[GvHelper.ATTR_TOTAL_COUNT] = (list != null) ? list.Count.ToString() : "0";
            this.gv_list.DataBind();
            this.gv_list.BottomPagerRow.Visible = true;
        }
        protected void btn_Query_Click(object sender, EventArgs e) {
            LoadUsers();
        }
        protected void gvPager_OnSelectedIndexChanged(object sender, EventArgs e) {
            DropDownList ddl = (DropDownList)sender;
            this.gv_list.PageIndex = Convert.ToInt32(ddl.SelectedValue)-1;
            LoadUsers();
        }
        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e) {
            this.gv_list.PageIndex = e.NewPageIndex;
            LoadUsers();
        }
        protected void gv_list_Sorting(object sender, GridViewSortEventArgs e) { 
        
        }

    }
}